//
//  UIBarButtonItem+Extension.swift
//  Weibo
//
//  Created by Northwan on 16/1/20.
//  Copyright © 2016年 Northwan. All rights reserved.
//

import UIKit

let ItemTitleColor: UIColor = UIColor(white: 80/255, alpha: 1)

let ItemTitleSize: UIFont = UIFont.systemFontOfSize(15)

extension UIBarButtonItem{

    convenience init(imgName:String? = nil,title:String? = nil,target: AnyObject?, action: Selector) {
        self.init()
        
        let button = UIButton()
        //添加事件
        button.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        
        
        //设置背景图片
        if let img = imgName{
            button.setImage(UIImage(named: img) , forState: .Normal)
            button.setImage(UIImage(named:"\(img)_highlighted"), forState:.Highlighted)
        }
        
        //设置文字
        if let t = title{
            button.setTitle(t, forState: .Normal)
            button.setTitleColor(ItemTitleColor, forState: .Normal)
            button.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
            button.titleLabel?.font = ItemTitleSize
        }
    
        button.sizeToFit()
        
        customView = button
    }
}
